package com.smile.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smile.data.dto.ProductMenuQueryDto
import com.smile.data.entity.ProductMenuEntity
import com.smile.mapper.ProductMenuMapper
import com.smile.response.ResultEmpty
import com.smile.response.ResultPage
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
 class ProductMenuService {
    @Autowired
    lateinit var mapper : ProductMenuMapper;

    fun  query(dto: ProductMenuQueryDto) : ResultPage<ProductMenuEntity> {
        var page = Page<ProductMenuEntity>(dto.page, dto.size);
        var query = QueryWrapper<ProductMenuEntity>();
        query.allEq(
            mapOf(
                "status" to dto.status,
                "menu" to dto.menu
            ),false
        );
        return mapper.selectPage(page, query).run { ResultPage(page)}
    }

    fun queryById(id: String) :ProductMenuEntity {
        return mapper.selectById(id)
    }

    fun create(dto: ProductMenuEntity) : ResultEmpty {
        return  mapper.insert(dto).run { ResultEmpty() };
    }

    fun update(id: String, dto: ProductMenuEntity) : ResultEmpty{
        return mapper.updateById(dto).run { ResultEmpty() }
    }

    fun remove(id: String) : ResultEmpty{
      return mapper.deleteById(id).run { ResultEmpty() }
    }


}
